const http = require("http")
const fs = require("fs")

const APK_PATH = "platforms/android/app/build/outputs/apk/debug/app-debug.apk"
const HOSTNAME = "172.16.121.198"
const PORT = 9001

function main() {
  const server = http.createServer((req, resp) => {
    console.log(req.url)

    resp.statusCode = 200

    if (req.url === "/check-version") {
      resp.end("new version", "utf-8")
      return
    }

    let stream = fs.createReadStream(APK_PATH)
    stream.pipe(resp)

    stream.on("end", () => {
      console.log("done")
    })
  })

  server.listen(PORT, HOSTNAME, () => {
    console.log("\nserver started")
  })
}

main()
